<template>
	<view class="content">
		<bgyx-nav-bar>
			<view slot="left">
				<u-icon @click="goback" name="arrow-left" size="36"></u-icon>
			</view>
			<view slot="default">
				<b style="font-size: 32rpx;">发布</b>
			</view>
			<view slot="right" style="display: flex;justify-content: flex-end;align-items: center;">
				<u-button @click="pubInfo" type="success" size="mini">发布</u-button>
			</view>
		</bgyx-nav-bar>
		<view style="border-bottom: 1rpx solid #eeeeee;">
			<u-input v-model="value" type="textarea" :border="false" :height="120" :auto-height="true" />
		</view>
		<u-upload max-count="9" ref="ref" :action="action" name="image" :on-change="onChange" :file-list="fileList"></u-upload>
	</view>
</template>

<script>
	import config from '../../config.js'
	export default {
		data() {
			return {
				value: '',
				action: config.hostUrl + "/upload/upload/uploadImage",
				fileList: []
			}
		},
		methods: {
			goback:function(){
				uni.switchTab({
					url:"/pages/friends/index"
				})
			},
			pubInfo: async function() {
				console.log(123321)
				const files = this.$refs.ref.lists.filter(val => {
					return val.progress == 100 && val.response && val.response.success;
				}).map(e=>e.response.data.pathname)
				const user_id = this.$store.state.user.user.id
				const data = {
					content:this.value,
					images:files,
					user_id
				}
				uni.showLoading({
					title:"发布中..."
				})
				const ret = await this.$u.post(`friend/friend/pubPyqInfo`,data)
				uni.hideLoading()
				if(ret.success){
					this.$store.dispatch({
						type:"friend/refreshListForce",
						payload:{}
					})
					uni.showToast({
						title:"发布成功",
					})
					this.goback()
				}else{
					uni.showToast({
						title:"发布失败",
						icon:"none"
					})
				}
				
			},
			onChange: function(res) {
				console.log(res, this.fileList)
			}
		}
	}
</script>

<style scoped>
	.content {
		padding: 25rpx;
		width: 100%;
		display: flex;
		flex-direction: column;
	}
</style>